package com.aooci.ordercat.desktop.view;

import java.net.URL;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;

import javafx.print.PrinterJob;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.DatePicker;
import javafx.scene.control.ChoiceBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import com.aooci.ordercat.desktop.OrdercatMain;
import com.aooci.ordercat.domain.Ordercat;
import com.aooci.ordercat.enums.OrderStatus;
import com.aooci.ordercat.vo.ItemVo;
import com.aooci.ordercat.vo.OperatedOrderVo;
import com.aooci.ordercat.vo.OrdercatVo;
import com.aooci.ordercat.vo.RecetteVo;
import com.aooci.ordercat.vo.TakeawayVo;

@SuppressWarnings("restriction")
public class RecetteController implements Initializable {

	private OrdercatMain ordercatMain;
	private VBox page;
	//private List<RecetteVo> recetteList;
	
	// Item table
    @FXML private TableView<RecetteVo> recetteTable;
    @FXML private TableColumn<RecetteVo, String> indexColumn;
    @FXML private TableColumn<RecetteVo, String> cashColumn;
    @FXML private TableColumn<RecetteVo, String> cardColumn;
    @FXML private TableColumn<RecetteVo, String> chequeColumn;
    @FXML private TableColumn<RecetteVo, String> tva6Column;
    @FXML private TableColumn<RecetteVo, String> tva12Column;
    @FXML private TableColumn<RecetteVo, String> tva21Column;
    @FXML private TableColumn<RecetteVo, String> paidTotalColumn;


	@FXML private Label givingChangeAmount;
    
	@FXML private Button printButton;
	@FXML private Button closeButton;


	@FXML
	public void initialize(URL arg0, ResourceBundle arg1) {
		
    	// Initialize the item table.
		indexColumn.setCellValueFactory(cellData -> cellData.getValue().indexProperty());
		cashColumn.setCellValueFactory(cellData -> cellData.getValue().cashProperty());
		cardColumn.setCellValueFactory(cellData -> cellData.getValue().cardProperty());
		chequeColumn.setCellValueFactory(cellData -> cellData.getValue().chequeProperty());
		tva6Column.setCellValueFactory(cellData -> cellData.getValue().tva6Property());
		tva12Column.setCellValueFactory(cellData -> cellData.getValue().tva12Property());
		tva21Column.setCellValueFactory(cellData -> cellData.getValue().tva21Property());
		paidTotalColumn.setCellValueFactory(cellData -> cellData.getValue().paidTotalProperty());
		//orderedItemAmountColumn.setCellValueFactory(cellData -> cellData.getValue().amountProperty());
		//orderedItemTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> setSelectedOrderedItemVo(newValue));
		
		this.closeButton.setOnAction((event) -> {
			((Stage) this.closeButton.getScene().getWindow()).close();
		});
		
	}


	public void init(OrdercatMain ordercatMain, VBox page, List<RecetteVo> recetteList) {
		this.ordercatMain = ordercatMain;
		this.page = page;
		this.recetteTable.setItems(FXCollections.observableArrayList(recetteList));
	}

	
	@FXML
	public void print(){
		
		//Node node = new Circle(100, 200, 200);
		PrinterJob job = PrinterJob.createPrinterJob();
		if (job != null) {
		   boolean success = job.printPage(page);
		   if (success) {
		       job.endJob();
		   }
		}
	}
}
